/*
1:安装 vue-router
2:src/router/index.ts
3:import {createRouter,createWebHashHistory} from 'vue-router'
4:实例化
   const router=createRouter({
       history:createWebHashHistory(),
       routes:[]
   })
5:暴露  export default router
6:在main.ts挂载
  import router from '..'  
  createApp(App).use(router).mount('#app')
7:路由出口
   router-view
*/

import { createRouter, createWebHashHistory } from 'vue-router'

const router = createRouter({
  history: createWebHashHistory(),
  routes: [
    {
      path: '/login',
      component: () => import('@/views/login/index.vue')
    },
    {
      path: '/playGround',
      component: () => import('@/views/playGround/index.vue'),
      beforeEnter (to, from) {
        console.log('beforeEnter')
      }
    },

    {
      path: '/',
      redirect: '/home',
      component: () => import('@/views/layout/index.vue'),
      children: [
        {
          path: '/home',
          component: () => import('@/views/home/index.vue')
        },
        {
          path: '/category/:id',
          component: () => import('@/views/category/index.vue')
        },
        {
          path: '/category/sub/:id',
          component: () => import('@/views/category/sub.vue')
        },
        {
          path: '/goods/:id',
          component: () => import('@/views/goods/index.vue')
        }
      ]
    }
  ]
})
// 前置守卫
router.beforeEach((to, from, next) => {
  // console.log('beforeEach')
  next()
})
// 后置守卫
router.afterEach(() => {
  // console.log('afterEach')
})
// 解析前守卫
router.beforeResolve((to, from) => {
  // console.log('beforeResolve')
})

export default router
